1295A - Display The Number - CodeForces Solution


greedy *900

Please click on ads to support us..

Python Code:

t = int(input())
other = ['9', '7']
pr = {'7': 1, '9': 4}
for _ in range(t):
    n = int(input())
    l = min((n//2, 998244353))
    output = ['1'] * l
    n -= 2*l
    for i in range(l):
        for new in other:
            if n >= pr[new]:
                output[i] = new
                n -= pr[new]
                break
    print(int(''.join(output)))

C++ Code:

#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll =  long long;
const int N = 1e5;
const int mod = 1000000007;

template<typename... T>
void read(T&... args) {
   ((cin >> args), ...);
}

template<typename... T>
void write(T&&... args) {
   ((cout << args << " "), ...);
}

int32_t main(){
   time_t start, end;
   time(&start);
   ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(12) << fixed;
   ll t; read(t);
   while(t--){
   	ll n; read(n);
   	string k = "";
   	if(n&1) k.push_back('7');
    for(ll i=0;i<n;i+=2){
    	if(n&1 && i==0) {
    		i++;
    		continue;
    	}
    	k.push_back('1');
    }

    write(k);
      

      cout<<endl;
   }


   time(&end);
   // double time_taken = double(end - start);
   // cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
   // cout << " sec " << endl; 
   return 0;
}


Comments

Submit
0 Comments
More Questions

1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum
519A - A and B and Chess
725B - Food on the Plane